package com.example.sharding.service;

import com.example.sharding.entity.Order;
import com.example.sharding.repository.OrderRepository;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class OrderService {

    private final OrderRepository orderRepository;

    public OrderService(OrderRepository orderRepository) {
        this.orderRepository = orderRepository;
    }

    public void createOrder(Order order) {
        // order_id 由ShardingSphere的雪花算法自动生成
        orderRepository.save(order);
    }

    public List<Order> getOrdersByUser(Integer userId) {
        return orderRepository.findByUserId(userId);
    }

    public List<Order> getOrdersByTimeRange(Date start, Date end) {
        return orderRepository.findByCreateTimeBetween(start, end);
    }
}
